package java_thinking.unit_21._21_5;

import java.util.concurrent.*;

/**
 * @Desc:
 * @author: cww
 * @DateTime: 2020/5/13 14:19
 */

public class TestThread {
    public static final ThreadPoolExecutor poolExecutor =
            new ThreadPoolExecutor(2, 2, 60,
                    TimeUnit.SECONDS, new LinkedBlockingQueue<>(3),
                    new ThreadPoolExecutor.AbortPolicy());



    public static void main(String[] args) {

        Ts s= new Ts();
        poolExecutor.execute(s);

    }
}

class Ts extends Thread{
    /**
     *
     */
    @Override
    public void run() {
        CountDownLatch templateLatch = new CountDownLatch(3);
        System.out.println("a");
        TestThread.poolExecutor.execute(new Ts1(templateLatch));

        System.out.println("finished");
        TestThread.poolExecutor.execute(new Ts1(templateLatch));

        TestThread.poolExecutor.execute(new Ts1(templateLatch));

        try {
            templateLatch.await();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("finished");


    }
}
class Ts1 extends Thread{

    private CountDownLatch templateLatch;

    /**
     */
    public Ts1(CountDownLatch templateLatch) {
        this.templateLatch = templateLatch;
    }

    /**
     *
     */
    @Override
    public void run() {
        System.out.println("b");
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        templateLatch.countDown();
    }
}
